package com.tsd.system.utils;

import java.awt.*;
import java.util.Random;

/**
 * @author Hillpool
 */
public class RandomUtils extends org.apache.commons.lang3.RandomUtils {

    private static final char[] CODE_SEQ = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
            'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9'};

    private static final char[] NUMBER_ARRAY = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    private static final Random RANDOM = new Random();

    private static final int INT_255 = 255;

    public static String randomString(int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(CODE_SEQ[RANDOM.nextInt(CODE_SEQ.length)]);
        }
        return sb.toString();
    }

    public static String randomNumberString(int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(NUMBER_ARRAY[RANDOM.nextInt(NUMBER_ARRAY.length)]);
        }
        return sb.toString();
    }

    public static Color randomColor(int fc, int bc) {
        Random random = new Random();
        if (fc > INT_255) {
            fc = INT_255;
        }
        if (bc > INT_255) {
            bc = INT_255;
        }
        int r = fc + random.nextInt(bc - fc);
        int g = fc + random.nextInt(bc - fc);
        int b = fc + random.nextInt(bc - fc);
        return new Color(r, g, b);
    }

    public static int nextInt(int bound) {
        return RANDOM.nextInt(bound);
    }
}

